-module(protocol).

%%protocol:write_public_class_erlang().
%%write_ctrl:write(protocol,ptc_all_skill).
-export([set_file/1,write/1,write_public_class/1]).

set_file(Module) ->
	put(module,Module),	
	ok.

write(RdFile) ->
	write_c(),
	write_erlang(RdFile).

write_c() ->
	case get(module) of
		module -> {error,no_module};
		Module -> 
			write_c(Module)
	end.

write_erlang(RdFile) ->
	case get(module) of
		module -> {error,no_module};
		Module -> 
			write_erlang(Module,RdFile)
	end.

try_make_dir(Path) ->
	case filelib:is_dir(Path) of
		false -> file:make_dir(Path);
		_ -> ok
	end.

default_to_str([]) -> "[]";
default_to_str(Other) when erlang:is_atom(Other) -> erlang:atom_to_list(Other);
default_to_str(Other) when erlang:is_integer(Other) -> erlang:integer_to_list(Other);
default_to_str(Other) when erlang:is_float(Other) -> erlang:float_to_list(Other);
default_to_str(Other) when erlang:is_atom(Other) -> erlang:atom_to_list(Other);
default_to_str(_Other) -> 0.
													 
check_new_name(int8,_Add) -> "int8";
check_new_name(uint8,_Add) -> "uint8";
check_new_name(int16,_Add) -> "int16";
check_new_name(uint16,_Add) -> "uint16";
check_new_name(int32,_Add) -> "int32";
check_new_name(uint32,_Add) -> "uint32";
check_new_name(int64,_Add) -> "int64";
check_new_name(uint64,_Add) -> "uint64";
check_new_name(string,_Add) -> "string";
check_new_name(float,_Add) -> "float";
check_new_name({list,int8},_Add) -> "{list,int8}";
check_new_name({list,uint8},_Add) -> "{list,uint8}";
check_new_name({list,int16},_Add) -> "{list,int16}";
check_new_name({list,uint16},_Add) -> "{list,uint16}";
check_new_name({list,int32},_Add) -> "{list,int32}";
check_new_name({list,uint32},_Add) -> "{list,uint32}";
check_new_name({list,int64},_Add) -> "{list,int64}";
check_new_name({list,uint64},_Add) -> "{list,uint64}";
check_new_name({list,string},_Add) -> "{list,string}";
check_new_name({list,float},_Add) -> "{list,float}";
check_new_name({list,Class},Add) -> "{list," ++ erlang:atom_to_list(Class) ++ Add ++ "}";
check_new_name(_Class,_Add) -> "error".

write_erlang(Module,RdFile) ->
	Name = Module:get_name(),
	DataDes = Module:get_des(),
	Id = Module:get_id(),
	CreateModule = "pt_" ++ erlang:atom_to_list(Name) ++ "_" ++ string:to_lower(erlang:integer_to_list(Id, 16)),
	Filename = "./erl/" ++ CreateModule ++ ".erl",
	try_make_dir("./erl"),
	case file:open(Filename, [write]) of
		{ok, File} ->
			file:write(File, "-module(" ++ CreateModule ++ ").\r\n"),
			file:write(File, "-include(\"pt.hrl\").\r\n\r\n"),
			
			file:write(File, "-export([new/0,from_binary/1,to_binary/1,to_binary/2,get_id/0]).\r\n"),
			
			file:write(File, "\r\n"),
			
			file:write(File, "get_id()-> 16#" ++ erlang:integer_to_list(Id, 16) ++ ".\r\n"),
			file:write(File, "\r\n"),
			
			make_erlang_new(File,Name),
			file:write(File, "\r\n"),
			
			make_erlang_from_binary(File,Name,DataDes),
			file:write(File, "\r\n"),
			
			make_erlang_to_binary(File,Name,DataDes),
			file:write(File, "\r\n"),

			file:close(File),
			
			RStr = "-record(pt_" ++ erlang:atom_to_list(Name) ++ ",{",
			FunMakeFun = fun({FieldName,_FieldType,FieldDefault},Str) -> Str ++ erlang:atom_to_list(FieldName) ++ "=" ++ default_to_str(FieldDefault) ++ "," end,
			RStr1 = lists:foldl(FunMakeFun, RStr, DataDes),
			RStr2 = case DataDes of
						[] -> RStr1;
						_ -> lists:sublist(RStr1, length(RStr1) - 1)
					end,			
			file:write(RdFile, RStr2 ++ "}).\r\n"),			
			ok;
		{error, Reason} -> io:format("write file error,filename=~s,r=~p\n",[Filename,Reason])
	end.

make_erlang_new(File,Name) ->
	file:write(File, "new()->#pt_" ++ erlang:atom_to_list(Name) ++"{}.\r\n"),
	ok.

make_erlang_from_binary(File,Name,DataDes) ->
	file:write(File, "from_binary(Binary) -> \r\n"),
	FunMake = fun({_FieldName,FieldType,_FieldDefault},{I,Max}) ->
					  From = if
								 I == 1 -> "Binary";
								 true -> "Binary" ++ erlang:integer_to_list(I - 1)
							 end,
					  To = if
								 I == Max -> "_Binary";
								 true -> "Binary" ++ erlang:integer_to_list(I)
							 end,
					  
					  
					  file:write(File, "\t{" ++ To ++ ",Data" ++ erlang:integer_to_list(I) ++ "}" ++ 
									 " = lib_protocol:from_binary(" ++ From ++ "," ++ check_new_name(FieldType,"_from_binary") ++ "),\r\n"),
					  {I + 1,Max}
			  end,
	lists:foldl(FunMake, {1,length(DataDes)}, DataDes),
	
	file:write(File, "\t#pt_" ++ erlang:atom_to_list(Name) ++ "{\r\n"),	
	FunSet = fun({FieldName,_FieldType,_FieldDefault},{I,Max}) ->
					  file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = Data" ++ erlang:integer_to_list(I)),
					  if
						  I == Max -> file:write(File,"\r\n");
						  true -> file:write(File,",\r\n")
					  end,
					  {I + 1,Max}
			  end,		
	lists:foldl(FunSet, {1,length(DataDes)}, DataDes),	
	file:write(File, "\t}.\r\n"),
	ok.
make_erlang_to_binary(File,Name,DataDes) ->
	file:write(File, "to_binary(Pt) -> to_binary(Pt,0).\r\n"),
	file:write(File, "to_binary(Pt,Seq) -> \r\n"),
	FunMake = fun({FieldName,FieldType,_FieldDefault},I) ->					  
					  file:write(File, "\tData" ++ erlang:integer_to_list(I) ++ 
									 " = lib_protocol:to_binary(Pt#pt_" ++ erlang:atom_to_list(Name) ++ "." ++
									  erlang:atom_to_list(FieldName) ++ "," ++ check_new_name(FieldType,"_to_binary") ++ "),\r\n"),
					  
					  I + 1
			  end,
	lists:foldl(FunMake, 1, DataDes),
	
	FunSet = fun({_FieldName,_FieldType,_FieldDefault},{I,Max,Str}) ->
					 This = "Data" ++ erlang:integer_to_list(I) ++ "/binary",
					 if
						 I == Max -> {I + 1,Max,Str ++ This};
						 true -> {I + 1,Max,Str ++ This ++ ","}
					 end
			 end,		
	{_,_,StrGet} = lists:foldl(FunSet, {1,length(DataDes),"<<"}, DataDes),
	file:write(File, "\tGetData = " ++ StrGet ++ ">>,\r\n"),
	file:write(File, "\tlib_protocol:make_pt(GetData,get_id(),Seq).\r\n"),
	ok.


write_c(Module) ->
	Name = Module:get_name(),
	DataDes = Module:get_des(),
	Id = Module:get_id(),
	CreateClass = "pt_" ++ erlang:atom_to_list(Name) ++ "_" ++ string:to_lower(erlang:integer_to_list(Id, 16)),
	Filename = "./c/" ++ CreateClass ++ ".cs",
	try_make_dir("./c"),
	case file:open(Filename, [write]) of
		{ok, File} ->
%% 			file:write(File, "using UnityEngine;\r\n"),
			file:write(File, "using System.Collections;\r\n"),
			file:write(File, "using System.Collections.Generic;\r\n"),
			file:write(File, "\r\n"),
			
			case erlang:function_exported(Module, get_note, 0) of
				true -> file:write(File, "/*\r\n" ++ Module:get_note() ++ "\r\n*/\r\n");
				_ -> skip
			end,
			
			file:write(File, "public class " ++ CreateClass ++ " : st.net.NetBase.Pt {\r\n"),
			
			file:write(File, "\tpublic " ++ CreateClass ++ "()\r\n"),
			file:write(File, "\t{\r\n"),
			file:write(File, "\t\tId = 0x" ++ erlang:integer_to_list(Id, 16) ++ ";\r\n"),
			file:write(File, "\t}\r\n"),
			
			file:write(File, "\tpublic override st.net.NetBase.Pt createNew()\r\n"),
			file:write(File, "\t{\r\n"),
			file:write(File, "\t\treturn new " ++ CreateClass ++ "();\r\n"),
			file:write(File, "\t}\r\n"),
	
			FunMakeFun = fun({FieldName,FieldType,FieldDefault}) -> make_c_fun(File,FieldName,FieldType,FieldDefault) end,
			lists:foreach(FunMakeFun, DataDes),
			
			
			make_c_from_binary(File,DataDes),
			file:write(File, "\r\n"),
			
			make_c_to_binary(File,DataDes),
			file:write(File, "\r\n"),
			
			file:write(File, "}\r\n"),
	
			file:close(File);			
		{error, Reason} -> io:format("write file error,filename=~s,r=~p\n",[Filename,Reason])
	end.
make_c_fun(File,ListFieldName,{list,int8},_ListFieldDefault) ->
	file:write(File, "\tpublic List<byte> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<byte>();\r\n");
make_c_fun(File,ListFieldName,{list,uint8},_ListFieldDefault) ->
	file:write(File, "\tpublic List<byte> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<byte>();\r\n");
make_c_fun(File,ListFieldName,{list,int16},_ListFieldDefault) ->
	file:write(File, "\tpublic List<short> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<short>();\r\n");
make_c_fun(File,ListFieldName,{list,uint16},_ListFieldDefault) ->
	file:write(File, "\tpublic List<ushort> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<ushort>();\r\n");
make_c_fun(File,ListFieldName,{list,int32},_ListFieldDefault) ->
	file:write(File, "\tpublic List<int> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<int>();\r\n");
make_c_fun(File,ListFieldName,{list,uint32},_ListFieldDefault) ->
	file:write(File, "\tpublic List<uint> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<uint>();\r\n");
make_c_fun(File,ListFieldName,{list,int64},_ListFieldDefault) ->
	file:write(File, "\tpublic List<long> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<long>();\r\n");
make_c_fun(File,ListFieldName,{list,uint64},_ListFieldDefault) ->
	file:write(File, "\tpublic List<ulong> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<ulong>();\r\n");
make_c_fun(File,ListFieldName,{list,string},_ListFieldDefault) ->
	file:write(File, "\tpublic List<string> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<string>();\r\n");
make_c_fun(File,ListFieldName,{list,float},_ListFieldDefault) ->
	file:write(File, "\tpublic List<float> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<float>();\r\n");
make_c_fun(File,ListFieldName,{list,double},_ListFieldDefault) ->
	file:write(File, "\tpublic List<double> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<double>();\r\n");
make_c_fun(File,ListFieldName,{list,ListDes},_ListFieldDefault) ->
	case ptc_public_class:get_des(ListDes) of
		no -> skip;
		_ -> 	
			file:write(File, "\tpublic List<st.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ 
						   "> " ++ erlang:atom_to_list(ListFieldName) ++ " = new List<st.net.NetBase." ++ 
						   erlang:atom_to_list(ListDes) ++ ">();\r\n")
	end;
make_c_fun(File,FieldName,int8,_FieldDefault) -> file:write(File, "\tpublic byte " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,uint8,_FieldDefault) -> file:write(File, "\tpublic byte " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,int16,_FieldDefault) -> file:write(File, "\tpublic short " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,uint16,_FieldDefault) -> file:write(File, "\tpublic ushort " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,int32,_FieldDefault) -> file:write(File, "\tpublic int " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,uint32,_FieldDefault) -> file:write(File, "\tpublic uint " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,int64,_FieldDefault) -> file:write(File, "\tpublic long " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,uint64,_FieldDefault) -> file:write(File, "\tpublic ulong " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,string,_FieldDefault) -> file:write(File, "\tpublic string " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,float,_FieldDefault) -> file:write(File, "\tpublic float " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(File,FieldName,double,_FieldDefault) -> file:write(File, "\tpublic double " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_fun(_File,_FieldName,_FieldType,_FieldDefault) -> ok.



make_c_from_binary_fun(File,FieldName,int8) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_byte();\r\n");
make_c_from_binary_fun(File,FieldName,uint8) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_byte();\r\n");
make_c_from_binary_fun(File,FieldName,int16) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_short();\r\n");
make_c_from_binary_fun(File,FieldName,uint16) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n");
make_c_from_binary_fun(File,FieldName,int32) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_int();\r\n");
make_c_from_binary_fun(File,FieldName,uint32) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_uint();\r\n");
make_c_from_binary_fun(File,FieldName,int64) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_long();\r\n");
make_c_from_binary_fun(File,FieldName,uint64) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ulong();\r\n");
make_c_from_binary_fun(File,FieldName,string) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_str();\r\n");
make_c_from_binary_fun(File,FieldName,float) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_float();\r\n");
make_c_from_binary_fun(File,FieldName,double) -> file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_double();\r\n");
make_c_from_binary_fun(File,FieldName,{list,int8}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<byte>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tbyte listData = reader.Read_byte();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,uint8}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<byte>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tbyte listData = reader.Read_byte();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,int16}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<short>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tshort listData = reader.Read_short();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,uint16}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<ushort>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tushort listData = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,int32}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<int>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tint listData = reader.Read_int();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,uint32}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<uint>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tuint listData = reader.Read_uint();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,int64}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<long>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tlong listData = reader.Read_long();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,uint64}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<ulong>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tulong listData = reader.Read_ulong();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,string}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<string>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tstring listData = reader.Read_str();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,float}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<float>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tfloat listData = reader.Read_float();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,double}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<double>();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tdouble listData = reader.Read_double();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(File,FieldName,{list,ListDes}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<st.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ ">();\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tst.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ " listData = new st.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ "();\r\n"),
	file:write(File, "\t\t\tlistData.fromBinary(reader);\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_from_binary_fun(_File,_FieldName,_FieldType) -> ok.

make_c_from_binary(File,DataDes) ->
	file:write(File, "\tpublic override void fromBinary(byte[] binary)\r\n"),
	file:write(File, "\t{\r\n"),
	file:write(File, "\t\treader = new st.net.NetBase.ByteReader(binary);\r\n"),
	FunMakeFun = fun({FieldName,FieldType,_FieldDefault}) -> make_c_from_binary_fun(File,FieldName,FieldType) end,
	lists:foreach(FunMakeFun, DataDes),
	file:write(File, "\t}\r\n"),
	ok.

make_c_to_binary_fun(File,FieldName,int8) -> file:write(File, "\t\twriter.write_byte(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,uint8) -> file:write(File, "\t\twriter.write_byte(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,int16) -> file:write(File, "\t\twriter.write_short(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,uint16) -> file:write(File, "\t\twriter.write_short(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,int32) -> file:write(File, "\t\twriter.write_int(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,uint32) -> file:write(File, "\t\twriter.write_int(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,int64) -> file:write(File, "\t\twriter.write_long(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,uint64) -> file:write(File, "\t\twriter.write_long(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,string) -> file:write(File, "\t\twriter.write_str(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,float) -> file:write(File, "\t\twriter.write_float(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,double) -> file:write(File, "\t\twriter.write_double(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_to_binary_fun(File,FieldName,{list,int8}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tbyte listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_byte(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,uint8}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tbyte listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_byte(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,int16}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tshort listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_short(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,uint16}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tushort listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_short(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,int32}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tint listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_int(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,uint32}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tuint listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_int(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,int64}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tlong listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_long(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,uint64}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tulong listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_long(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,string}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tstring listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_str(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,float}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tfloat listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_float(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,double}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tdouble listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\twriter.write_double(listData);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(File,FieldName,{list,ListDes}) -> 
	file:write(File, "\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t{\r\n"),
	file:write(File, "\t\t\tst.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ " listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\tlistData.toBinary(writer);\r\n"),
	file:write(File, "\t\t}\r\n");
make_c_to_binary_fun(_File,_FieldName,_FieldType) -> ok.

make_c_to_binary(File,DataDes) ->
	file:write(File, "\tpublic override byte[] toBinary()\r\n"),
	file:write(File, "\t{\r\n"),
	file:write(File, "\t\twriter = new st.net.NetBase.ByteWriter();\r\n"),
	FunMakeFun = fun({FieldName,FieldType,_FieldDefault}) -> make_c_to_binary_fun(File,FieldName,FieldType) end,
	lists:foreach(FunMakeFun, DataDes),
	file:write(File, "\t\treturn writer.data;\r\n"),
	file:write(File, "\t}\r\n"),
	ok.

write_public_class(RdFile) ->
	write_public_class_c(),
	write_public_class_erlang(RdFile).

write_public_class_c() ->
	CreateClass = "pt_public_class",
	try_make_dir("./c"),
	case file:open("./c/" ++ CreateClass ++ ".cs", [write]) of
		{ok, File} ->
			file:write(File, "using System.Collections;\r\n"),
			file:write(File, "using System.Collections.Generic;\r\n"),
			file:write(File, "\r\n"),
			
			file:write(File, "namespace st.net.NetBase\r\n"),
			file:write(File, "{\r\n"),
			List = ptc_public_class:get_all(),
			Fun = fun(Classs) ->
						  case ptc_public_class:get_des(Classs) of
							  no -> skip;
							  Des -> write_des_classs(File,Classs,Des)
						  end
				  end,						 
			lists:foreach(Fun, List),
			file:write(File, "}\r\n"),
			file:close(File);
		R -> R
	end.



write_public_class_erlang(RdFile) ->
	CreateModule = "pt_public_class",
	try_make_dir("./erl"),
	case file:open("./erl/" ++ CreateModule ++ ".erl", [write]) of
		{ok, File} ->
			file:write(File, "-module(" ++ CreateModule ++ ").\r\n"),
			file:write(File, "-include(\"pt.hrl\").\r\n\r\n"),
			
			List = ptc_public_class:get_all(),
			FunExp = fun(Classs) ->
						  case ptc_public_class:get_des(Classs) of
							  no -> skip;
							  Des -> 
								  file:write(File, "-export([" ++ erlang:atom_to_list(Classs) ++ "_new/0," ++ erlang:atom_to_list(Classs) ++ "_from_binary/1," 
											++ erlang:atom_to_list(Classs) ++ "_to_binary/1]).\r\n"),
								  
								  RStr = "-record(pt_public_" ++ erlang:atom_to_list(Classs) ++ ",{",
								  FunMakeFun = fun({FieldName,_FieldType,FieldDefault},Str) -> Str ++ erlang:atom_to_list(FieldName) ++ "=" ++ default_to_str(FieldDefault) ++ "," end,
								  RStr1 = lists:foldl(FunMakeFun, RStr, Des),
								  RStr2 = case Des of
											  [] -> RStr1;
											  _ -> lists:sublist(RStr1, length(RStr1) - 1)
										  end,
								  file:write(RdFile, RStr2 ++ "}).\r\n")
						  end
				  end,						 
			lists:foreach(FunExp, List),
			FunFun = fun(Classs) ->
						  case ptc_public_class:get_des(Classs) of
							  no -> skip;
							  Des -> 
								  file:write(File, "\r\n"),
								  
								  make_erlang_list_new(File,Classs),
								  make_erlang_list_from_binary(File,Classs,Des),
								  make_erlang_list_to_binary(File,Classs,Des)
						  end
				  end,						 
			lists:foreach(FunFun, List),
			file:write(File, "\r\n"),
			file:close(File);
		R -> R
	end.

make_c_list_fun(File,FieldName,int8,_FieldDefault) -> file:write(File, "\t\tpublic byte " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,uint8,_FieldDefault) -> file:write(File, "\t\tpublic byte " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,int16,_FieldDefault) -> file:write(File, "\t\tpublic short " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,uint16,_FieldDefault) -> file:write(File, "\t\tpublic ushort " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,int32,_FieldDefault) -> file:write(File, "\t\tpublic int " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,uint32,_FieldDefault) -> file:write(File, "\t\tpublic uint " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,int64,_FieldDefault) -> file:write(File, "\t\tpublic long " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,uint64,_FieldDefault) -> file:write(File, "\t\tpublic ulong " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,string,_FieldDefault) -> file:write(File, "\t\tpublic string " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,float,_FieldDefault) -> file:write(File, "\t\tpublic float " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,double,_FieldDefault) -> file:write(File, "\t\tpublic double " ++ erlang:atom_to_list(FieldName) ++ ";\r\n");
make_c_list_fun(File,FieldName,{list,int8},_FieldDefault) ->
	file:write(File, "\t\tpublic List<byte> " ++ erlang:atom_to_list(FieldName) ++ " = new List<byte>();\r\n");
make_c_list_fun(File,FieldName,{list,uint8},_FieldDefault) ->
	file:write(File, "\t\tpublic List<byte> " ++ erlang:atom_to_list(FieldName) ++ " = new List<byte>();\r\n");
make_c_list_fun(File,FieldName,{list,int16},_FieldDefault) ->
	file:write(File, "\t\tpublic List<short> " ++ erlang:atom_to_list(FieldName) ++ " = new List<short>();\r\n");
make_c_list_fun(File,FieldName,{list,uint16},_FieldDefault) ->
	file:write(File, "\t\tpublic List<ushort> " ++ erlang:atom_to_list(FieldName) ++ " = new List<ushort>();\r\n");
make_c_list_fun(File,FieldName,{list,int32},_FieldDefault) ->
	file:write(File, "\t\tpublic List<int> " ++ erlang:atom_to_list(FieldName) ++ " = new List<int>();\r\n");
make_c_list_fun(File,FieldName,{list,uint32},_FieldDefault) ->
	file:write(File, "\t\tpublic List<uint> " ++ erlang:atom_to_list(FieldName) ++ " = new List<uint>();\r\n");
make_c_list_fun(File,FieldName,{list,int64},_FieldDefault) ->
	file:write(File, "\t\tpublic List<long> " ++ erlang:atom_to_list(FieldName) ++ " = new List<long>();\r\n");
make_c_list_fun(File,FieldName,{list,uint64},_FieldDefault) ->
	file:write(File, "\t\tpublic List<ulong> " ++ erlang:atom_to_list(FieldName) ++ " = new List<ulong>();\r\n");
make_c_list_fun(File,FieldName,{list,string},_FieldDefault) ->
	file:write(File, "\t\tpublic List<string> " ++ erlang:atom_to_list(FieldName) ++ " = new List<string>();\r\n");
make_c_list_fun(File,FieldName,{list,float},_FieldDefault) ->
	file:write(File, "\t\tpublic List<float> " ++ erlang:atom_to_list(FieldName) ++ " = new List<float>();\r\n");
make_c_list_fun(File,FieldName,{list,double},_FieldDefault) ->
	file:write(File, "\t\tpublic List<double> " ++ erlang:atom_to_list(FieldName) ++ " = new List<double>();\r\n");
make_c_list_fun(File,FieldName,{list,ListDes},_FieldDefault) ->
	case ptc_public_class:get_des(ListDes) of
		no -> skip;
		_ -> 	
			file:write(File, "\t\tpublic List<st.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ 
						   "> " ++ erlang:atom_to_list(FieldName) ++ " = new List<st.net.NetBase." ++ 
						   erlang:atom_to_list(ListDes) ++ ">();\r\n")
	end.

make_c_list_fromBinary(File,FieldName,int8,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_byte();\r\n");
make_c_list_fromBinary(File,FieldName,uint8,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_byte();\r\n");
make_c_list_fromBinary(File,FieldName,int16,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_short();\r\n");
make_c_list_fromBinary(File,FieldName,uint16,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n");
make_c_list_fromBinary(File,FieldName,int32,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_int();\r\n");
make_c_list_fromBinary(File,FieldName,uint32,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_uint();\r\n");
make_c_list_fromBinary(File,FieldName,int64,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_long();\r\n");
make_c_list_fromBinary(File,FieldName,uint64,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ulong();\r\n");
make_c_list_fromBinary(File,FieldName,string,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_str();\r\n");
make_c_list_fromBinary(File,FieldName,float,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_float();\r\n");
make_c_list_fromBinary(File,FieldName,double,_FieldDefault) -> file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_double();\r\n");
make_c_list_fromBinary(File,FieldName,{list,int8},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<byte>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tbyte listData = reader.Read_byte();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,uint8},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<byte>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tbyte listData = reader.Read_byte();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,int16},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<short>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tshort listData = reader.Read_short();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,uint16},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<ushort>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tushort listData = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,int32},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<int>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tint listData = reader.Read_int();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,uint32},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<uint>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tuint listData = reader.Read_uint();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,int64},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<long>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tlong listData = reader.Read_long();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,uint64},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<ulong>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tulong listData = reader.Read_ulong();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,string},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<string>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tstring listData = reader.Read_str();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,float},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<float>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tfloat listData = reader.Read_float();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,double},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<double>();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tdouble listData = reader.Read_double();\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_fromBinary(File,FieldName,{list,ListDes},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = reader.Read_ushort();\r\n"),
	file:write(File, "\t\t\t" ++ erlang:atom_to_list(FieldName) ++ " = new List<st.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ ">();\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tst.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ " listData = new st.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ "();\r\n"),
	file:write(File, "\t\t\t\tlistData.fromBinary(reader);\r\n"),
	file:write(File, "\t\t\t\t" ++ erlang:atom_to_list(FieldName) ++ ".Add(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n").

make_c_list_toBinary(File,FieldName,int8,_FieldDefault) -> file:write(File, "\t\t\twriter.write_byte(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,uint8,_FieldDefault) -> file:write(File, "\t\t\twriter.write_byte(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,int16,_FieldDefault) -> file:write(File, "\t\t\twriter.write_short(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,uint16,_FieldDefault) -> file:write(File, "\t\t\twriter.write_short(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,int32,_FieldDefault) -> file:write(File, "\t\t\twriter.write_int(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,uint32,_FieldDefault) -> file:write(File, "\t\t\twriter.write_int(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,int64,_FieldDefault) -> file:write(File, "\t\t\twriter.write_long(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,uint64,_FieldDefault) -> file:write(File, "\t\t\twriter.write_long(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,string,_FieldDefault) -> file:write(File, "\t\t\twriter.write_str(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,float,_FieldDefault) -> file:write(File, "\t\t\twriter.write_float(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,double,_FieldDefault) -> file:write(File, "\t\t\twriter.write_double(" ++ erlang:atom_to_list(FieldName) ++ ");\r\n");
make_c_list_toBinary(File,FieldName,{list,int8},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tbyte listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_byte(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,uint8},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tbyte listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_byte(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,int16},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tshort listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_short(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,uint16},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tushort listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_short(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,int32},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tint listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_int(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,uint32},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tuint listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_int(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,int64},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tlong listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_long(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,uint64},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tulong listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_long(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,string},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tstring listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_str(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,float},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tfloat listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_float(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,double},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tdouble listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\twriter.write_double(listData);\r\n"),
	file:write(File, "\t\t\t}\r\n");
make_c_list_toBinary(File,FieldName,{list,ListDes},_FieldDefault) -> 
	file:write(File, "\t\t\tushort len" ++ erlang:atom_to_list(FieldName) ++ " = (ushort)" ++ erlang:atom_to_list(FieldName) ++ ".Count;\r\n"),
	file:write(File, "\t\t\twriter.write_short(len" ++ erlang:atom_to_list(FieldName) ++ ");\r\n"),
	file:write(File, "\t\t\tfor(int i_" ++ erlang:atom_to_list(FieldName) ++ " = 0 ; i_" ++ erlang:atom_to_list(FieldName) ++ " < len" ++ erlang:atom_to_list(FieldName) ++ " ; i_" ++ erlang:atom_to_list(FieldName) ++ " ++)\r\n"),
	file:write(File, "\t\t\t{\r\n"),
	file:write(File, "\t\t\t\tst.net.NetBase." ++ erlang:atom_to_list(ListDes) ++ " listData = " ++ erlang:atom_to_list(FieldName) ++ "[i_" ++ erlang:atom_to_list(FieldName) ++ "];\r\n"),
	file:write(File, "\t\t\t\tlistData.toBinary(writer);\r\n"),
	file:write(File, "\t\t\t}\r\n").

write_des_classs(File,Classs,Des)->
	file:write(File, "\tpublic class " ++ erlang:atom_to_list(Classs) ++ "\r\n"),
	file:write(File, "\t{\r\n"),
	
	FunMakeFun1 = fun({FieldName,FieldType,FieldDefault}) -> make_c_list_fun(File,FieldName,FieldType,FieldDefault) end,
	lists:foreach(FunMakeFun1, Des),
	
	file:write(File, "\t\tpublic void fromBinary(st.net.NetBase.ByteReader reader)\r\n"),
	file:write(File, "\t\t{\r\n"),
	
	FunMakeFun2 = fun({FieldName,FieldType,FieldDefault}) -> make_c_list_fromBinary(File,FieldName,FieldType,FieldDefault) end,
	lists:foreach(FunMakeFun2, Des),

	file:write(File, "\t\t}\r\n"),
	
	file:write(File, "\t\tpublic void toBinary(st.net.NetBase.ByteWriter writer)\r\n"),
	file:write(File, "\t\t{\r\n"),
	
	FunMakeFun3 = fun({FieldName,FieldType,FieldDefault}) -> make_c_list_toBinary(File,FieldName,FieldType,FieldDefault) end,
	lists:foreach(FunMakeFun3, Des),
	
	file:write(File, "\t\t}\r\n"),
	
	file:write(File, "\t}\r\n"),
	ok.


make_erlang_list_new(File,Class) ->
	file:write(File, erlang:atom_to_list(Class) ++ "_new()->#pt_public_" ++ erlang:atom_to_list(Class) ++ "{}.\r\n").

make_erlang_list_from_binary(File,Class,DataDes) -> 
	file:write(File, erlang:atom_to_list(Class) ++ "_from_binary(Binary) -> \r\n"),
	FunMake = fun({_FieldName,FieldType,_FieldDefault},{I,Max}) ->
					  From = if
								 I == 1 -> "Binary";
								 true -> "Binary" ++ erlang:integer_to_list(I - 1)
							 end,
					  To = if
								 I == Max -> "LastBinary";
								 true -> "Binary" ++ erlang:integer_to_list(I)
							 end,
					  
					  file:write(File, "\t{" ++ To ++ ",Data" ++ erlang:integer_to_list(I) ++ "}" ++ 
									 " = lib_protocol:from_binary(" ++ From ++ "," ++ check_new_name(FieldType,"_from_binary") ++ "),\r\n"),
					  {I + 1,Max}
			  end,
	lists:foldl(FunMake, {1,length(DataDes)}, DataDes),
	
	file:write(File, "\t{ok,LastBinary,#pt_public_" ++ erlang:atom_to_list(Class) ++ "{\r\n"),	
	FunSet = fun({FieldName,_FieldType,_FieldDefault},{I,Max}) ->
					  file:write(File, "\t\t" ++ erlang:atom_to_list(FieldName) ++ " = Data" ++ erlang:integer_to_list(I)),
					  if
						  I == Max -> file:write(File,"\r\n");
						  true -> file:write(File,",\r\n")
					  end,
					  {I + 1,Max}
			  end,		
	lists:foldl(FunSet, {1,length(DataDes)}, DataDes),	
	file:write(File, "\t}}.\r\n"),
	ok.

make_erlang_list_to_binary(File,Class,DataDes) ->
	file:write(File, erlang:atom_to_list(Class) ++ "_to_binary(Pt) -> \r\n"),
	FunMake = fun({FieldName,FieldType,_FieldDefault},I) ->					  
					  file:write(File, "\tData" ++ erlang:integer_to_list(I) ++ 
									 " = lib_protocol:to_binary(Pt#pt_public_" ++ erlang:atom_to_list(Class) ++ "." ++
									  erlang:atom_to_list(FieldName) ++ "," ++ check_new_name(FieldType,"_to_binary") ++ "),\r\n"),
					  
					  I + 1
			  end,
	lists:foldl(FunMake, 1, DataDes),
	
	FunSet = fun({_FieldName,_FieldType,_FieldDefault},{I,Max,Str}) ->
					 This = "Data" ++ erlang:integer_to_list(I) ++ "/binary",
					 if
						 I == Max -> {I + 1,Max,Str ++ This};
						 true -> {I + 1,Max,Str ++ This ++ ","}
					 end
			 end,		
	{_,_,StrGet} = lists:foldl(FunSet, {1,length(DataDes),"<<"}, DataDes),
	file:write(File, "\t" ++ StrGet ++ ">>.\r\n"),
	ok.
	